import request from "@/utils/request";
import type { ResponseData } from "@/api/user/type";
import type { TradeMarkResponseData } from "@/api/product/trademark/type";
import type { UserInfo, RoleUsersResponse, SetRoleUser } from "./type";
enum API {
  //获取管理用户分页列表
  USERDATA_URL = "/admin/acl/user/",
  //添加用户
  ADDUSER_URL = "/admin/acl/user/save",
  //修改用户
  UPDATEUSER_URL = "/admin/acl/user/update",
  //根据用户获取角色数据
  ROLEUSER_URL = "/admin/acl/user/toAssign/",
  //给已有的用户分配角色
  SETROLEUSER_URL = "/admin/acl/user/doAssignRole",
  //删除用户账号
  REMOVEUSER_URL = "/admin/acl/user/remove/",
  //批量删除用户账号
  BATCHREMOVEUSER_URl = "/admin/acl/user/batchRemove",
}
//获取管理用户分页列表
export const reqHasUserData = (
  page: number | string,
  limit: number | string,
  username: string
) => {
  return request.get<any, ResponseData<TradeMarkResponseData<UserInfo>>>(
    `${API.USERDATA_URL}${page}/${limit}/?username=${username}`
  );
};

//新增用户｜修改用户
export const reqAddOrUpdateUser = (data: UserInfo) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, data);
  } else {
    return request.post<any, any>(API.ADDUSER_URL, data);
  }
};
//根据用户获取角色数据
export const reqRoleUserData = (adminId: number | string) => {
  return request.get<any, ResponseData<RoleUsersResponse>>(
    API.ROLEUSER_URL + `${adminId}`
  );
};
//给已有的用户分配角色
export const reqSetRoleUser = (data: SetRoleUser) => {
  return request.post<any, any>(API.SETROLEUSER_URL, data);
};
//删除用户账号
export const reqRemoveUser = (id: number) => {
  return request.delete<any, any>(API.REMOVEUSER_URL + `${id}`);
};
//批量删除用户账号
export const reqBatchRemoveUser = (idList: number[]) => {
  return request.delete<any, any>(API.BATCHREMOVEUSER_URl, { data: idList });
};
